package cn.rui.decoration.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.rui.decoration.mapper.OrdersMapper;
import cn.rui.decoration.pojo.dto.OrdersDTO;
import cn.rui.decoration.pojo.entity.Orders;
import cn.rui.decoration.pojo.vo.OrdersVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@RestController
public class OrdersController {
    @Autowired(required = false)
    OrdersMapper mapper;
    @RequestMapping("/orders/insert")
    public void insert(@RequestBody OrdersDTO orders, HttpSession session) {
        session.getAttribute("user");
        Orders o = new Orders();
        BeanUtils.copyProperties(orders,o);
        o.setDate(new Date());
        mapper.insert(o);
    }
    @RequestMapping("/orders/selectById/detail")
    public List<OrdersVO> selectById(int id){
        return mapper.selectById(id);
    }
    @RequestMapping("/deleteById")
    public void deleteById(int id){
        mapper.deleteById(id);
    }
}
